import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.substitutions import LaunchConfiguration
from launch_ros.actions.node import Node
from unicodedata import name

def generate_launch_description():
    # Path
    bt_xml_dir = os.path.join(get_package_share_directory('turtle_bt_ros2'), 'bt_xml')

    # Parameters
    bt_xml = LaunchConfiguration('bt_xml', default=bt_xml_dir+'/bt_npcturtle.xml')

    turtle1_my = Node(
        package='turtle_bt_ros2',
        node_executable='turtle_bt_ros2_node',
        node_name='my_turtle',
        output='screen'
    )

    turtle2_npc = Node(
        package='turtle_bt_ros2',
        node_executable='client',
        node_name='NPC_turtle',
        output='screen'
    )

    turtle1_tf = Node(
        package='turtle_bt_ros2',
        node_executable='myturtle_tf_broadcaster',
        node_name='tf_turtle1',
        output='screen'
    )

    turtle2_tf = Node(
        package='turtle_bt_ros2',
        node_executable='npcturtle_tf_broadcaster',
        node_name='tf_turtle2',
        output='screen'
    )

    behavior_tree = Node(
        package='turtle_bt_ros2',
        node_executable='bt_turtle2_tree',
        parameters=[{'bt_xml': bt_xml}],
        output='screen'
    )

    ld = LaunchDescription()
    ld.add_action(turtle1_my)
    ld.add_action(turtle2_npc)
    ld.add_action(turtle1_tf)
    ld.add_action(turtle2_tf)
    ld.add_action(behavior_tree)
    
    return ld